package com.niodata.dp.web;

import java.util.Map;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public class ExecuteTimeInterceptor implements MethodInterceptor {

  @Override
  public Object invoke(MethodInvocation methodInvocation) throws Throwable {
    long start = System.currentTimeMillis();
    Object obj = methodInvocation.proceed();
    long end = System.currentTimeMillis();
    double timeUsed = (end - start) / 1000d;
    if (obj.getClass().isAssignableFrom(Map.class)) {
      Map map = (Map) obj;
      map.put("TimeUsed", timeUsed);
    }
    return obj;
  }
}
